package com.open.capacity.exam.service.impl;

import com.open.capacity.common.model.ExamQuestionsSubject;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.exam.dao.QuestionSubjectDao;
import com.open.capacity.exam.service.QuestionSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class QuestionSubjectServiceImpl implements QuestionSubjectService {
    @Autowired
    private QuestionSubjectDao subjectDao;

    /**
     * 条件查询
     * @param subject
     * @return
     */
    @Override
    public PageResult<ExamQuestionsSubject> findAll(Map<String,Object> subject) {
        PageUtil.pageParamConver(subject,false);
        List<ExamQuestionsSubject> list= subjectDao.findAll(subject);
        int count= subjectDao.findAllCount(subject);
        return PageResult.<ExamQuestionsSubject>builder().data(list).count((long)count).build();
    }

    /**
     * 添加科目
     * @param subject
     * @return
     */
    @Override
    public Result addSubject(ExamQuestionsSubject subject) {
        Integer insert= subjectDao.insert(subject);
        return insert>0?Result.succeed("添加成功"):Result.failed("操作失败");
    }

    /**
     * 修改科目
     * @param subject
     * @return
     */
    @Override
    public Result editSubject(ExamQuestionsSubject subject) {
        Integer update= subjectDao.update(subject);
        return update>0?Result.succeed("修改成功"):Result.failed("操作失败");
    }
}
